package jkernel;

import java.util.StringJoiner;

public class StringJoinerClass {
    public static void main(String[] args) {

        String[] fields = { "name", "position", "salary" };
        String table = "employee";
        String select = buildSelectSql(table, fields);
        System.out.println(select);
        System.out.println("SELECT name, position, salary FROM employee".equals(select) ? "测试成功" : "测试失败");

        String[] names = {"Bob", "Alice", "Grace"};
        StringJoiner sj = new StringJoiner(", ", "Hello ", "!" );
        for (String name : names) {
            sj.add(name);
        }
        String s = String.join(", ", names);
        System.out.println(s);
        System.out.println(sj.toString());
    }


    static String buildSelectSql(String table, String[] fields) {
        return "SELECT " + String.join(", ", fields) + " FROM " + table;
    }
}
